#include "RenderingProcesser.hpp"
#include "RenderWindow.hpp"

#include <thread>
#include <chrono>

static double deltaTime = 0;

namespace phx
{

RenderingProcesser::RenderingProcesser() : 
	mWindows()
{

}

void RenderingProcesser::addWindow(RenderWindow *window)
{
	mWindows.push_back(window);
}

void RenderingProcesser::process()
{
	//double startTime = glfwGetTime();
	for(std::vector<RenderWindow*>::iterator it = mWindows.begin(); it != mWindows.end();)
	{
		RenderWindow *window = *it;
		if(!window->isOpen())
		{
			it = mWindows.erase(it);
		}
		else
		{
			if(window->mRenderCallbackFunc)
				window->mRenderCallbackFunc(*window, 15);
			it++;
		}
	}
	std::this_thread::sleep_for(std::chrono::milliseconds(10));
	//deltaTime = glfwGetTime() - startTime;
}

void RenderingProcesser::destroy()
{
	mWindows.clear();
}

}